package com.example;

class Channel{
	public int int_val;
	public String str_val;
	public boolean ready;
	public Channel(){
		ready = true;
	}
	public synchronized boolean Send(int a, String str){
		if(ready==false) return false; 
		this.int_val = a;
		this.str_val = str;
		ready = false;
		return true;
	}
	public synchronized boolean receive(Channel ch){
		if(ready == true) return false;
		ch.int_val = this.int_val;
		ch.str_val = this.str_val;
		ready = true;
		return true;
	}
}
class Input extends Thread{
	public Channel ch;
	public Input(Channel ch){
		this.ch = ch;
	}
	public void run(){
		Channel inp = new Channel();
		for(int j = 0; j < 10; j++){
			while(ch.receive(inp) == false){
			//	System.out.println("Receiving");
			}
		}
		System.out.println("Input complete");
	}
}
class Output extends Thread{
	public Channel ch;
	public Output(Channel ch){
		this.ch = ch;
	}
	public void run(){
		for(int i = 0; i < 10; i++){
			while(ch.Send(i, "hello") == false){
				System.out.println("Send "+i);
			}
		}
		System.out.println("Sending complete");
	}
}
public class InpOutput{
	public static void main(String args[]){
		Channel channel = new Channel();
		Input inp = new Input(channel);
		Output output = new Output(channel);
		inp.start(); output.start();
	}
}